# -*- encoding=utf8 -*-

__author__ = "code哥"
import json
from sanic.blueprints import Blueprint
from sanic.views import HTTPMethodView
from sanic import response
from sanic_openapi import doc
from conn_pool import get_redis, REDIS_NEXT_DAY_EXECUTION_TIME

rs = get_redis()

blueprint = Blueprint(__name__, '/api')


class NextDayExecutionTime(HTTPMethodView):

    @doc.summary("获取程序下一天开始执行时间")
    def post(self, request):
        redis_next_day_exec_time = rs.get(REDIS_NEXT_DAY_EXECUTION_TIME)
        if redis_next_day_exec_time is not None and len(str(redis_next_day_exec_time)) > 0:
            next_day_exec_time = json.loads(redis_next_day_exec_time, encoding='utf-8')
            return response.json({'code': 0, 'data': next_day_exec_time})
        return response.json({'code': 0, 'data': {}})


blueprint.add_route(NextDayExecutionTime.as_view(), '/next_day_exec_time', strict_slashes=True)
